import request from '@/common/request'
import useUserStore from '@/store/user'
import type { AnyObject, TRequestData, TStrOrNum } from '@/common/types'

// 登录
export function login(code: string, data?: AnyObject) {
  return request.get('/api/user/jscode2session', { code, ...data })
}

// 获取首页数据
export function getHomeData() {
  return request.get('/api/index/index')
}

// 搜索页猜你喜欢
export function getSearchLike() {
  return request.get('/api/search/index')
}

// 搜索结果
export function getSearch(data:TRequestData) {
  return request.get('/api/search/search', data)
}

// 首页换一换
export function homeRefresh(cateid: number) {
  return request.get('/api/index/refresh', { cateid })
}

// 获取用户余额
export function getBalance() {
  const userStore = useUserStore()
  return request.get('/api/user/getbalance', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid')
  })
}

// 获取用户会员信息
export function getVipInfo() {
  const userStore = useUserStore()
  return request.get('/api/user/kaitong', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid')
  })
}

// 获取剧详情
export function getDetail(album_id: string, data?: AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/index/bofang', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    album_id,
    ...data
  })
}

// 追剧列表
export function getBingeWatch(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/user/zhuiju', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 消费明细
export function getConsumption(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/user/xiaofei', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 充值明细
export function getTopUp(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/user/chongzhi', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 获取历史
export function getHistory(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/user/history', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 用币解锁
export function unlockByCoin(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/index/bfl', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 获取广告参数
export function getAd() {
  return request.get('/api/index/getad')
}

// 广告解锁
export function unlockByAd(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/index/guanggaoUnlock', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 追剧
export function setBingeWatch(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/index/zhuiju', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 点赞
export function setLikes(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/index/likes', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 获取签到列表
export function getSingInList() {
  const userStore = useUserStore()
  return request.get('/api/qiandao/index', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid')
  })
}

// 签到
export function singIn() {
  const userStore = useUserStore()
  return request.get('/api/qiandao/qiandao', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid')
  })
}

// 剩余观看广告次数
export function getResidueAdvertisement() {
  const userStore = useUserStore()
  return request.get('/api/renwu/shengyucishu', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid')
  })
}

// 获取观看广告奖励
export function getAdvertisementRewards() {
  const userStore = useUserStore()
  return request.get('/api/renwu/guankan', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid')
  })
}

// 获取任务奖励
export function getQuestRewards(id: number) {
  const userStore = useUserStore()
  return request.get('/api/renwu/desk', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    id
  })
}

// 获取充值规格
export function getGoods(album_id?: TStrOrNum) {
  return request.get('/api/goods/index', {
    album_id
  })
}

// 获取任务列表
export function getQuest() {
  return request.get('/api/renwu/index')
}

// 调起支付
export function getPay(data:AnyObject) {
  const userStore = useUserStore()
  return request.get('/api/order/create', {
    userid: userStore.userId || uni.getStorageSync('orange-music-theatre-userid'),
    ...data
  })
}

// 登录
export function login1(code:TRequestData) {
  return request.post('/api/user/jscode2session', { code })
}
